import http from "@/API/index";
import type {Banner} from "@/models/banner";
import type {TopListDetail} from "@/models/toplist_detail";
import type {SongUrl} from "@/models/song_url";
import type {Song} from "@/models/song";
import type {Artist} from "@/models/artist"
import type {PlayListDetail, PlaylistHighqualityTag} from "@/models/playlist"
import type {SearchSuggest, SearchHotDetail} from "@/models/search";
import {Personalized, PersonalizedNewSong, PersonalizedMv, DjProgram} from "@/models/personalized";
import {Video, PersonalizedPrivateContent} from "@/models/video";

export const useBanner = async () => {
    const {banners} = await http.get<{ banners: Banner[] }>('/banner', {type: 1});
    return banners;
};
export const useTopListDetail = async () => {
    const {list} = await http.get<{ list: TopListDetail[] }>('/toplist/detail');
    return list;
};

export const usePersonalized = async () => {
    const {result} = await http.get<{ result: Personalized[] }>("/personalized");
    return result;
};
export const usePersonalizedNewSong = async () => {
    const {result} = await http.get<{ result: PersonalizedNewSong[] }>('/personalized/newsong');
    return result;
};

export const useSongUrl = async (id: number) => {
    const {data} = await http.get<{ data: SongUrl[] }>("/song/url", {id: id});
    return data.first();
};
export const useDetail = async (id: number) => {
    const {songs} = await http.get<{ songs: Song[] }>('/song/detail', {ids: id});
    return songs.first();
};

export const useSearchSuggest = async (keywords: string) => {
    const {result} = await http.get<{ result: SearchSuggest }>('search/suggest', {keywords: keywords});
    return result
};
export const useSearchHotDetail = async () => {
    const {data} = await http.get<{ data: SearchHotDetail[] }>('search/hot/detail')
    return data
};

export const useMvUrl = async () => {

};
export const useVideoTimelineRecommend = async (offset: number = 0) => {
    const {datas} = await http.get<{ datas: Video[] }>('video/timeline/recommend', {offset: offset});
    return datas;
};

//个性化推荐mv
export const usePersonalizedMv = async () => {
    const {result} = await http.get<{ result: PersonalizedMv[] }>('personalized/mv')
    return result;
};

export const usePersonalizedPrivateContentList = async (limit: number = 10, offset: number = 0) => {
    const {result} = await http.get<{ result: PersonalizedPrivateContent[] }>('personalized/privatecontent/list', {
        limit: limit,
        offset: offset
    });
    return result;
};

export const usePersonalizedDjProgram = async () => {
    const {result} = await http.get<{ result: DjProgram [] }>('personalized/djprogram');
    return result;
};

export const userArtistList = async (pageData: { type: number, area: number, initial: string, page: number, limit: number }) => {
    const res = await http.get<{ artists: Artist[] }>("artist/list", {
        type: pageData.type,
        area: pageData.area,
        initial: pageData.initial,
        limit: pageData.limit,
        offset: (pageData.page - 1) * pageData.limit
    });
    return res.artists
};
//获取分类歌单的tags接口
export const usePlaylistHighQualityTags = async () => {
    const {tags} = await http.get<{ tags: PlaylistHighqualityTag[] }>("playlist/highquality/tags");
    return tags;
};

//获取分类歌单的全部歌单
export const useTopPlaylistHighquality = async (params?: { limit?: number, before?: number, cat: string }) => {
    return await http.get<{ playlists: PlayListDetail[], total: number, more: boolean, lasttime: number }>("top/playlist/highquality", params)
};
